package com.tobeface.wechat.message.payload;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.tobeface.wechat.message.WeChatMessageBuilder;
import com.tobeface.wechat.message.WeChatMessagePayloads;
import com.tobeface.wechat.message.WeChatMessageTypes;

import java.util.List;
import java.util.Map;

/**
 * @author loudyn
 */
public class OutNewsMessagePayloadBuilder extends AbstractMessagePayloadBuilder {

    private List<Map<String, String>> newitems = Lists.newArrayList();
    private Map<String, String> curitem;

    /**
     * @param parent
     */
    public OutNewsMessagePayloadBuilder(WeChatMessageBuilder parent) {
        super(parent);
    }

    /**
     * @return
     */
    public OutNewsMessagePayloadBuilder item() {
        curitem = Maps.newHashMap();
        newitems.add(curitem);
        return this;
    }

    /**
     * @param title
     * @return
     */
    public OutNewsMessagePayloadBuilder title(String title) {
        curitem.put(WeChatMessagePayloads.TITLE_PAYLOAD, title);
        return this;
    }

    /**
     * @param descr
     * @return
     */
    public OutNewsMessagePayloadBuilder descr(String descr) {
        curitem.put(WeChatMessagePayloads.DESCR_PAYLOAD, descr);
        return this;
    }

    /**
     * @param picUrl
     * @return
     */
    public OutNewsMessagePayloadBuilder picUrl(String picUrl) {
        curitem.put(WeChatMessagePayloads.PICURL_PAYLOAD, picUrl);
        return this;
    }

    /**
     * @param url
     * @return
     */
    public OutNewsMessagePayloadBuilder url(String url) {
        curitem.put(WeChatMessagePayloads.URL_PAYLOAD, url);
        return this;
    }

    @Override
    protected void configPayloads(Map<String, Object> payloads) {
        payloads.put(WeChatMessagePayloads.MSGTYPE_PAYLOAD, WeChatMessageTypes.NEWS);
        payloads.put("ArticleCount", newitems.size());
        payloads.put("Artices", newitems);
    }
}
